<%@ Control Language="c#" AutoEventWireup="true" Inherits="Portal.API.EditModule" %>
<%@ Register TagPrefix="portal" Assembly="Portal.API" Namespace="Portal.API.Controls" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">

	private string GetPath()
	{
		return ModuleDataPhysicalPath + ModuleRef + ".htm";
	}

	void Page_Load(object sender, EventArgs args)
	{
		if (!IsPostBack)
		{
			if (File.Exists(GetPath()))
			{
				using (FileStream fs = File.OpenRead(GetPath()))
				{
					StreamReader sr = new StreamReader(fs);
					txt.Text = sr.ReadToEnd();
				}
			}
		}
	}

	void OnSave(object sender, EventArgs args)
	{
		if (Portal.API.HtmlAnalyzer.HasScriptTags(txt.Text))
		{
			msg.Error = Portal.API.Language.GetText(this, "ErrorScriptTags");
			return;
		}
		using (FileStream fs = new FileStream(GetPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
		{
			fs.SetLength(0);
			using (StreamWriter sw = new StreamWriter(fs))
			{
				sw.Write(txt.Text);
			}
		}
		RedirectBack();
	}

</script>
<portal:Message ID="msg" runat="server" />
<asp:TextBox ID="txt" Width="100%" Height="300px" TextMode="MultiLine" runat="server" />
<portal:LinkButton CssClass="LinkButton" runat="server" OnClick="OnSave" ID="Linkbutton1"
	LanguageRef="SaveBack" />
